package 矩阵.旋转图像;

import java.util.Arrays;

/**
 * TODO
 *
 * @className: xztx
 * @description: TODO
 * @author: 等什么柠檬君
 * @date: 2022-05-01 14:30
 **/
public class xztx {
    public static void main(String[] args) {
        int arr[][] = {{1,2,3},{4,5,6},{7,8,9}};
        rotate(arr);
    }
    public static void rotate(int[][] matrix) {

        Arrays.asList(matrix).forEach(item->{
            System.out.println(Arrays.toString(item));
        });
        System.out.println();
        for (int i = 0; i < matrix.length; i++) {
            for (int j = i; j < matrix[i].length ; j++) {
                System.out.println("-");
                int temp = 0;
                temp = matrix[i][j];
                matrix[i][j] = matrix[j][i];
                matrix[j][i] = temp;
            }
        }
        for (int i = 0; i < matrix.length; i++) {
            int[] arr = new int[matrix[i].length];
            for (int j = matrix[i].length-1; j >= 0; j--) {
                arr[matrix[i].length-1-j] = matrix[i][j];
            }
            matrix[i] = arr;
        }
        Arrays.asList(matrix).forEach(item->{
            System.out.println(Arrays.toString(item));
        });
    }
}
